package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.gzh.entity.TempSend;
import com.egao.gzh.service.SettingGzh;
import com.egao.orderB.entity.Message;
import com.egao.orderB.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 * 消息
 * @author : Doman
 * @date : 2021-07-14 10:39:02
 * @version ：1.0
 */

@Api(tags = "消息")
@RestController
@RequestMapping("/api/orderB/message")
public class MessageController extends BaseController {

	@Autowired
	private MessageService messageService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:message:list')")
    //@OperLog(value = "消息", desc = "分页查询")
    @ApiOperation(value ="分页查询消息",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        "customerReceiver:接受客户 传id 必填\n" +
        "type:类型 必填\n" +
        "参数传 billState 表示运单状态修改\n" +
        "参数传 customerFee 表示客户费用修改\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "content:内容\n" +
        "sender:发送人\n" +
        "sendTime:发送时间\n" +
        "customerReceiver:接受客户\n" +
        "receiver:接收人\n" +
        "type:类型:运单\n" +
        "state:状态 未读,已读\n" +
        "orderNum:排序\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, Message message) throws Exception{
        return messageService.list(page, message, getLoginUser());
    }

    /**
     * 查询全部消息
     */
    @PreAuthorize("hasAuthority('orderB:message:list')")
    //@OperLog(value = "消息", desc = "查询全部")
    @ApiOperation("查询全部消息")
    @PostMapping("/list")
    public JsonResult list(Message message){
        return messageService.list(message, getLoginUser());
    }

    /**
     * 根据id查询消息
     */
    @PreAuthorize("hasAuthority('orderB:message:list')")
    //@OperLog(value = "消息", desc = "根据id查询")
    @ApiOperation("根据id查询消息")
    @PostMapping("/get")
    public JsonResult get(Message message) {
        return messageService.getById(message);
		// 使用关联查询
        //PageParam<message> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<message> records = messageService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }

    /**
     * 根据id查询消息
     */
    @PreAuthorize("hasAuthority('orderB:message:list')")
    //@OperLog(value = "消息", desc = "根据id查询")
    @ApiOperation("根据id查询消息")
    @PostMapping("/testGzh")
    public void testGzh(String toUser, String templateId, String first) {
        SettingGzh cm = new SettingGzh();
        TempSend tempSend2 = new TempSend();
        tempSend2.setTouser(toUser);//owHBe6MpBnAikS4ZJWMJjmN5hpUk
        tempSend2.setTemplateId(templateId);//NmUIzARvtGDHaxf8PpXjMpU3H-Qy_5ZTj7St51Wd56s
        tempSend2.setFirst(first);//测试~~~车牌:浙B1R159, 司机:禾滕 已到厂
        tempSend2.setKeyword1("2021-01-01 12:23:10");
        tempSend2.setKeyword2("鄞州大道2段");
        tempSend2.setRemark("状态:已到厂");
        tempSend2.setUrl("https://gzhsy.sszgjzx.com/trace");
        cm.setPrivateTemplate(tempSend2);
		// 使用关联查询
        //PageParam<message> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<message> records = messageService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加消息
     */
    @PreAuthorize("hasAuthority('orderB:message:save')")
    @OperLog(value = "消息", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加消息",notes = "" +
            "content:内容\n" +
            "sender:发送人\n" +
            "sendTime:发送时间\n" +
            "customerReceiver:接受客户\n" +
            "receiver:接收人\n" +
            "type:类型:运单\n" +
            "state:状态 未读,已读\n" +
            "orderNum:排序\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, Message message) {
        return messageService.save(message, getLoginUser());
    }

    /**
     * 修改消息
     */
    @PreAuthorize("hasAuthority('orderB:message:update')")
    @OperLog(value = "消息", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改消息",notes = "" +
            "id:id\n" +
            "content:内容\n" +
            "sender:发送人\n" +
            "sendTime:发送时间\n" +
            "customerReceiver:接受客户\n" +
            "receiver:接收人\n" +
            "type:类型:运单\n" +
            "state:状态 未读,已读\n" +
            "orderNum:排序\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, Message message) {
        return messageService.update(message, getLoginUser());
    }

    /**
     * 删除消息
     */
    @PreAuthorize("hasAuthority('orderB:message:remove')")
    @OperLog(value = "消息", desc = "删除", result = true)
    @ApiOperation("删除消息")
    @PostMapping("/remove")
    public JsonResult remove(Message message ) {
        return messageService.remove(message, getLoginUser());
    }

    /**
     * 批量添加消息
     */
    /**@RequiresPermissions("orderB:message:save")
    @OperLog(value = "消息", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Message> list) {
        if (messageService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改消息
     */
    /**@RequiresPermissions("orderB:message:update")
    @OperLog(value = "消息", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Message> batchParam) {
        if (batchParam.update(messageService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除消息
     */
    /**@RequiresPermissions("orderB:message:remove")
    @OperLog(value = "消息", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (messageService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
